package main

import (
	"../pipeline"
	"bufio"
	"fmt"
	"os"
)

var (
	file1 = "small.in"
	file2 = "large.in"
)

func main() {
	file, err := os.Create(file1)

	if err != nil {
		panic(err)
	}

	defer file.Close()

	n := 64
	p := pipeline.RadomSource(n)
	writer := bufio.NewWriter(file)
	pipeline.WriteSink(writer, p)
	writer.Flush()

	file, err = os.Open(file1)
	if err != nil {
		panic(err)
	}

	p = pipeline.ReaderSource(
		bufio.NewReader(file), -1)

	count := 0
	for v := range p {
		fmt.Println(v)
		count++
		if count > 100 {
			break
		}
	}
}

func MergeDemo() {

	p := pipeline.Merge(
		pipeline.InMemSort(
			pipeline.ArraySource(
				3, 2, 1, 7, 4, 6, 9, 8)),
		pipeline.InMemSort(
			pipeline.ArraySource(
				8, 11, 2, 17, 14, 16, 9, 18)))

	/*
		if num, ok := <- p; ok {
			fmt.Println(num)
		}*/

	for v := range p {
		fmt.Println(v)
	}
}
